<template>
  <div class="app-container">
    
     <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="店铺" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入店铺"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="旺旺" prop="buyerNick">
        <el-input
          v-model="queryParams.buyerNick"
          placeholder="请输入旺旺"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
          size="small"
        >
           <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="评价类型" prop="evalutionType">
        <el-select
          v-model="queryParams.evalutionType"
          placeholder="请选择评价类型"
          clearable
          size="small"
        >
           <el-option
            v-for="dict in rebatesTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="生效时间" prop="dateSuchType">
            <el-radio v-model="queryParams.dateSuchType" label="oneMonth">30</el-radio>
            <el-radio v-model="queryParams.dateSuchType" label="twoMonth">60</el-radio>
      </el-form-item> -->
       <!-- <el-form-item label="付款日期" prop="tastDate">
        <el-date-picker
          clearable
          size="small"
          v-model="queryParams.tradingType"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item> -->
      
     <el-form-item label="评价日期" prop="creat">
        <el-date-picker
          v-model="datePick"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
 <el-row :gutter="10" class="mb8">
   <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column label="店铺名" align="center" prop="storeName" />
      <el-table-column label="产品名" align="center" prop="productName" />
      <el-table-column label="淘宝订单号" align="center" prop="orderNo" />
      <el-table-column label="旺旺号" align="center" prop="buyerNick" />
      <el-table-column label="微信号" align="center" prop="wxCode" />
      <el-table-column label="刷单负责人" align="center" prop="userName" />
      <el-table-column label="付款日期" align="center" prop="paymentTime"  />
      <!-- <el-table-column label="评价日期" align="center" prop="createTime" /> -->
      <el-table-column label="评价类型" align="center" prop="evalutionType" :formatter="rebatesTypeFormat" />
      <el-table-column label="任务状态" align="center" prop="status" :formatter="rebatesStatusFormat" />
       <el-table-column label="评价时间" align="center" prop="updateTime"  />
      <el-table-column label="操作" align="center"  >
        <template slot-scope="scope">
          <!-- <el-button @click="querenHandel(scope.row)" type="danger" v-if="scope.row.status =='0'">已{{rebatesTypeFormat(scope.row)}}</el-button>
           -->
           <div>
              <el-button @click="querenHandel(scope.row,'pj')" type="danger" v-if="scope.row.status=='0'">已评价</el-button>
              <el-button @click="querenHandel(scope.row,'zp')" type="danger" v-if="scope.row.evalutionType=='0' && scope.row.status=='1'">已追评</el-button>
          </div>
        </template>
      </el-table-column>
      
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
  </div>
</template>

<script>
import {  evalutiontasklist,changeTaskStatu,yizhuiping,exportevalutionReport } from "@/api/system/detail";

export default {
  name: "Detail",
  components: {
  },
  data() {
    return {
      checked:false,
      taskData:{},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务完成明细表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 交易类型字典
      tradingTypeOptions: [],
      // 订单类型字典
      orderTypeOptions: [],
      // 返款类型字典
      rebatesTypeOptions: [],
       // 任务状态字典
      statusOptions: [],
      // 用户类型字典
      buyerTypeOptions: [],
      // 返款渠道字典
      rebatesChannelOptions: [],
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeName:null,
        productName:null,
        taskName:null,
        buyerNick:null,
        evalutionType:null,
        evaluation_task_status:null,
        endTime: null,
        startTime: null,
      },
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      datePick: [],
     
    };
  },
  created() {
    // console.log(this.$route.params.id)
    // if(this.$route.params.row){
    //    this.taskData = this.$route.params.row
    // }
    this.getList();
    this.getDicts("trading_type").then(response => {
      this.tradingTypeOptions = response.data;
    });
    this.getDicts("order_type").then(response => {
      this.orderTypeOptions = response.data;
    });
    this.getDicts("pingjia_type").then(response => {
      this.rebatesTypeOptions = response.data;
    });
    this.getDicts("workbench_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("user_type").then(response => {
      this.buyerTypeOptions = response.data;
    });
    this.getDicts("channel_type").then(response => {
      this.rebatesChannelOptions = response.data;
    });
    this.getDicts("evaluation_task_status").then(response => {
      this.statusOptions = response.data;
    });
  },
   watch: {
    datePick: {
      handler: function (val, oldval) {
        if (val != null) {
          this.queryParams.startTime = this.parseTime(val[0], "{y}-{m}-{d}");
          this.queryParams.endTime = this.parseTime(val[1], "{y}-{m}-{d}");
        }
      },
    },
  },
  methods: {
    resetQuery(){
      this.queryParams= {
        pageNum: 1,
        pageSize: 10,
        storeName:null,
        productName:null,
        taskName:null,
        buyerNick:null,
        evalutionType:null,
        evaluation_task_status:null,
      }
    },
    /** 查询任务完成明细列表 */
    getList() {
      this.loading = true;
      evalutiontasklist(this.queryParams).then(response => {
        console.log(response)
        // this.taskData=response.rows;
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 确认操作
    querenHandel(row,type){
      let params ={
        id:row.id,
        status:1,
        // status:row.evalutionType
      }
      // 评价按钮
      if(type==='pj'){
        changeTaskStatu(params).then(res=>{
          this.$message.success("操作成功！");
          this.getList();
        })
      } else if(type==='zp'){
        // 追评按钮
          yizhuiping(params).then(res=>{
            this.$message.success("操作成功！");
            this.getList();
          })
      }
    },
    // 交易类型字典翻译
    tradingTypeFormat(row, column) {
      return this.selectDictLabel(this.tradingTypeOptions, row.tradingType);
    },
    // 订单类型字典翻译
    orderTypeFormat(row, column) {
      return this.selectDictLabel(this.orderTypeOptions, row.orderType);
    },
    // 返款类型字典翻译
    rebatesTypeFormat(row, column) {
      return this.selectDictLabel(this.rebatesTypeOptions, row.evalutionType);
    },
     // 返款类型字典翻译
    rebatesStatusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 用户类型字典翻译
    buyerTypeFormat(row, column) {
      return this.selectDictLabel(this.buyerTypeOptions, row.buyerType);
    },
    // 返款渠道字典翻译
    rebatesChannelFormat(row, column) {
      return this.selectDictLabel(this.rebatesChannelOptions, row.rebatesChannel);
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        taskDetailId: null,
        taskId: null,
        tradingVolume: null,
        buyerNick: null,
        tradingType: null,
        orderType: null,
        rebatesType: null,
        buyerType: null,
        rebatesChannel: null,
        rebatesWay: null,
        rebatesAmount: null,
        status: "0",
        responsibleUserId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.taskDetailId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加任务完成明细";
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有操作任务?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportevalutionReport(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>

<style lang="scss">
.detail-table{
  width: 100%;
  td{
    line-height: 25px;
    font-size: 14px;
    text-align: left;
    border-top: 1px solid #ccc;
    padding: 0 10px;
    color: #444;
    &:nth-child(odd){
      background: #e9e9e9;
      width:100px;
      text-align: right;
      font-weight: bold;
    }
  }
}
</style> 